package com.chaosj.xml;

import cn.hutool.json.JSONObject;
import com.dcits.webservice.client.S2001100000101.S2001100000101Request;
import lombok.extern.slf4j.Slf4j;
import java.util.HashMap;
import java.util.Map;

/**
 * @className: RemoteService
 * @description:
 * @author: caoyangjie
 * @date: 2022/5/15
 **/
@Slf4j
public class RemoteService {
    private static ApolloClientTool<RemoteRpcServiceEntry> apolloClientTool = new ApolloClientTool(new ApolloOpen());

    public static void main(String[] args) {
//        try {
//            List<String> allLines = Files.readAllLines(new ClassPathResource("/application.yml").getFile().toPath());
//            String prefix = "njcb.remote.function.";
//            Set<String> allServiceCode = allLines.stream().map(line->{
//                String appendLine = line.replaceFirst(prefix,"");
//                if( appendLine.contains(".") ){
//                    return appendLine.substring(0,appendLine.indexOf("."));
//                }
//                return "";
//            }).collect(Collectors.toSet());
//            allServiceCode.forEach(serviceCode->{
//                allLines.stream().filter(line->line.contains(serviceCode)).forEach(line->{
//
//                });
//                String interfaceName =
//            });
//            System.out.println("");
//        } catch (IOException e) {
//            log.error(e.getMessage());
//        }
//        new ApolloUtil();
//        ApolloOpenApiClient.newBuilder().withPortalUrl(apolloOpen.getPortal())
//                .withToken(apolloOpen.getToken()).build();
        apolloClientTool.getReleaseData("sofa","njcb.remote.function", RemoteRpcServiceEntry.class);
        S2001100000101Request request = new S2001100000101Request();
//        execute("2001300000296", new Object[]{request});

//        apolloClientTool.update("njcb.remote.function.2001300000296.interfaceName","njcb.remote.function","com.sofastack.stockmng.BalanceMngFacade", services);
        while (true){
            Thread.yield();
        }
    }

    public static JSONObject execute(String serviceCode, Object[] request){
        apolloClientTool.getRemoteService().get(serviceCode).invoke(request);
        return null;
    }
}
